# 使用官方Node镜像作为基础镜像
FROM node:20.9.0 AS builder

# 设置工作目录
WORKDIR /app

# 设置淘宝镜像registry
RUN npm config set registry https://registry.npmmirror.com

# 复制package.json和package-lock.json
COPY package*.json ./

# 安装依赖
RUN npm install -g pnpm
RUN pnpm install

# 复制项目文件
COPY . .

# 构建项目
RUN pnpm run build

# 使用Nginx作为生产服务器
FROM nginx:alpine

# 从builder阶段复制构建好的文件到Nginx目录
COPY --from=builder /app/dist /usr/share/nginx/html

# 暴露7002端口
EXPOSE 7002

# 启动Nginx
CMD ["nginx", "-g", "daemon off;"]